<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="140px">
      <el-form-item label="公司编码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入公司编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入公司名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商编码" prop="vendCode">
        <el-input
          v-model="queryParams.vendCode"
          placeholder="请输入供应商编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商名称" prop="vendName">
        <el-input
          v-model="queryParams.vendName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="办公地址" prop="actualAddress">
        <el-input
          v-model="queryParams.actualAddress"
          placeholder="请输入办公地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:genComTypePO:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="genComTypePOList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" v-if="false"/>
      <el-table-column label="公司编码" align="center" prop="code" />
      <el-table-column label="公司名称" align="center" prop="name" />
      <el-table-column label="供应商编码" align="center" prop="vendCode" />
      <el-table-column label="供应商名称" align="center" prop="vendName" />
      <el-table-column label="公司状态" align="center" prop="status" />
      <el-table-column label="国家" align="center" prop="country" />
      <el-table-column label="法定代表人" align="center" prop="comCorporation" />
      <el-table-column label="营业期限开始日期" align="center" prop="openDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.openDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="营业期限结束日期" align="center" prop="closeDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.closeDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="统一社会信用代码" align="center" prop="socialcreditCode" />
      <el-table-column label="注册地址" align="center" prop="address" />
      <el-table-column label="经营范围" align="center" prop="bizScope" />
      <el-table-column label="经营状态" align="center" prop="bizStatus" />
      <el-table-column label="注册资本" align="center" prop="registeredCapital" />
      <el-table-column label="实缴资本" align="center" prop="paidinCapital" />
      <el-table-column label="成立日期" align="center" prop="foundDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.foundDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="纳税人资质" align="center" prop="taxPayerType" />
      <el-table-column label="企业类型" align="center" prop="enterpriseType" />
      <el-table-column label="法人证件类型" align="center" prop="corporationCredentialType" />
      <el-table-column label="法人证件号" align="center" prop="corporationCredentialCode" />
      <el-table-column label="法定代表人证件复印件" align="center" prop="corporationCredentialCopy" />
      <el-table-column label="法定代表人联系电话" align="center" prop="corporationCredentialPhone" />
      <el-table-column label="办公地址" align="center" prop="actualAddress" />
      <el-table-column label="营业执照扫描件" align="center" prop="bizLicenseScan" />
      <el-table-column label="公司类型" align="center" prop="comType" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:genComTypePO:edit']"
          >修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改公司配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司编码" prop="code">
          <el-input v-model="form.code" placeholder="请输入公司编码" />
        </el-form-item>
        <el-form-item label="公司名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="供应商编码" prop="vendCode">
          <el-input v-model="form.vendCode" placeholder="请输入供应商编码" />
        </el-form-item>
        <el-form-item label="供应商名称" prop="vendName">
          <el-input v-model="form.vendName" placeholder="请输入供应商名称" />
        </el-form-item>
        <el-form-item label="国家" prop="country">
          <el-input v-model="form.country" placeholder="请输入国家" />
        </el-form-item>
        <el-form-item label="法定代表人" prop="comCorporation">
          <el-input v-model="form.comCorporation" placeholder="请输入法定代表人" />
        </el-form-item>
        <el-form-item label="营业期限开始日期" prop="openDate">
          <el-date-picker clearable
            v-model="form.openDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择营业期限开始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="营业期限结束日期" prop="closeDate">
          <el-date-picker clearable
            v-model="form.closeDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择营业期限结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="socialcreditCode">
          <el-input v-model="form.socialcreditCode" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="注册地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入注册地址" />
        </el-form-item>
        <el-form-item label="经营范围" prop="bizScope">
          <el-input v-model="form.bizScope" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="注册资本" prop="registeredCapital">
          <el-input v-model="form.registeredCapital" placeholder="请输入注册资本" />
        </el-form-item>
        <el-form-item label="实缴资本" prop="paidinCapital">
          <el-input v-model="form.paidinCapital" placeholder="请输入实缴资本" />
        </el-form-item>
        <el-form-item label="成立日期" prop="foundDate">
          <el-date-picker clearable
            v-model="form.foundDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择成立日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="法人证件号" prop="corporationCredentialCode">
          <el-input v-model="form.corporationCredentialCode" placeholder="请输入法人证件号" />
        </el-form-item>
        <el-form-item label="法定代表人证件复印件" prop="corporationCredentialCopy">
          <el-input v-model="form.corporationCredentialCopy" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="法定代表人联系电话" prop="corporationCredentialPhone">
          <el-input v-model="form.corporationCredentialPhone" placeholder="请输入法定代表人联系电话" />
        </el-form-item>
        <el-form-item label="办公地址" prop="actualAddress">
          <el-input v-model="form.actualAddress" placeholder="请输入办公地址" />
        </el-form-item>
        <el-form-item label="营业执照扫描件" prop="bizLicenseScan">
          <el-input v-model="form.bizLicenseScan" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGenComTypePO, getGenComTypePO, delGenComTypePO, addGenComTypePO, updateGenComTypePO } from "@/api/system/genComTypePO"

export default {
  name: "GenComTypePO",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公司配置表格数据
      genComTypePOList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        name: null,
        vendCode: null,
        vendName: null,
        status: null,
        country: null,
        comCorporation: null,
        openDate: null,
        closeDate: null,
        socialcreditCode: null,
        address: null,
        bizScope: null,
        bizStatus: null,
        registeredCapital: null,
        paidinCapital: null,
        foundDate: null,
        taxPayerType: null,
        enterpriseType: null,
        corporationCredentialType: null,
        corporationCredentialCode: null,
        corporationCredentialCopy: null,
        corporationCredentialPhone: null,
        actualAddress: null,
        bizLicenseScan: null,
        comType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        code: [
          { required: true, message: "公司编码不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "公司名称不能为空", trigger: "blur" }
        ],
        vendCode: [
          { required: true, message: "供应商编码不能为空", trigger: "blur" }
        ],
        vendName: [
          { required: true, message: "供应商名称不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "公司状态不能为空", trigger: "change" }
        ],
        country: [
          { required: true, message: "国家不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询公司配置列表 */
    getList() {
      this.loading = true
      listGenComTypePO(this.queryParams).then(response => {
        this.genComTypePOList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        name: null,
        vendCode: null,
        vendName: null,
        status: null,
        country: null,
        comCorporation: null,
        openDate: null,
        closeDate: null,
        socialcreditCode: null,
        address: null,
        bizScope: null,
        bizStatus: null,
        registeredCapital: null,
        paidinCapital: null,
        foundDate: null,
        taxPayerType: null,
        enterpriseType: null,
        corporationCredentialType: null,
        corporationCredentialCode: null,
        corporationCredentialCopy: null,
        corporationCredentialPhone: null,
        actualAddress: null,
        bizLicenseScan: null,
        comType: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加公司配置"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getGenComTypePO(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改公司配置"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGenComTypePO(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addGenComTypePO(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除公司配置编号为"' + ids + '"的数据项？').then(function() {
        return delGenComTypePO(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/genComTypePO/export', {
        ...this.queryParams
      }, `genComTypePO_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
